package com.ruoyi.project.system.service.impl;

import java.util.List;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.mapper.SocialUserconnectionMapper;
import com.ruoyi.project.system.domain.SocialUserconnection;
import com.ruoyi.project.system.service.ISocialUserconnectionService;

/**
 * 第三方授权Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-04-15
 */
@Service
public class SocialUserconnectionServiceImpl extends ServiceImpl<SocialUserconnectionMapper, SocialUserconnection> implements ISocialUserconnectionService
{
    @Autowired
    private SocialUserconnectionMapper socialUserconnectionMapper;

    /**
     * 查询第三方授权
     * 
     * @param userid 第三方授权ID
     * @return 第三方授权
     */
    @Override
    public SocialUserconnection selectSocialUserconnectionById(String userid)
    {
        return socialUserconnectionMapper.selectSocialUserconnectionById(userid);
    }

    /**
     * 查询第三方授权列表
     * 
     * @param socialUserconnection 第三方授权
     * @return 第三方授权
     */
    @Override
    public List<SocialUserconnection> selectSocialUserconnectionList(SocialUserconnection socialUserconnection)
    {
        return socialUserconnectionMapper.selectSocialUserconnectionList(socialUserconnection);
    }

    /**
     * 新增第三方授权
     * 
     * @param socialUserconnection 第三方授权
     * @return 结果
     */
    @Override
    public int insertSocialUserconnection(SocialUserconnection socialUserconnection)
    {
        socialUserconnection.setCreateTime(DateUtils.getNowDate());
        return socialUserconnectionMapper.insertSocialUserconnection(socialUserconnection);
    }

    /**
     * 修改第三方授权
     * 
     * @param socialUserconnection 第三方授权
     * @return 结果
     */
    @Override
    public int updateSocialUserconnection(SocialUserconnection socialUserconnection)
    {
        return socialUserconnectionMapper.updateSocialUserconnection(socialUserconnection);
    }

    /**
     * 批量删除第三方授权
     * 
     * @param userids 需要删除的第三方授权ID
     * @return 结果
     */
    @Override
    public int deleteSocialUserconnectionByIds(String[] userids)
    {
        return socialUserconnectionMapper.deleteSocialUserconnectionByIds(userids);
    }

    public int  delBindingSocialUser(String userid, String providerid, String provideruserid) {
        Assert.notBlank(userid);
        Assert.notBlank(providerid);
        Assert.notBlank(provideruserid);
        return this.baseMapper.delete(new LambdaQueryWrapper<SocialUserconnection>()
                                    .eq(SocialUserconnection::getUserid, userid)
                                    .eq(SocialUserconnection::getProviderId, providerid)
                                    .eq(SocialUserconnection::getProviderUserId, provideruserid));
    }

    /**
     * 删除第三方授权信息
     * 
     * @param userid 第三方授权ID
     * @return 结果
     */
    @Override
    public int deleteSocialUserconnectionById(String userid)
    {
        return socialUserconnectionMapper.deleteSocialUserconnectionById(userid);
    }
}
